package com.zyj.test.month2.day1;

import com.zyj.test.ListNode;

/**
 * @author Yijia Zhang
 * @create 2024-11-20 22:01
 */
public class Code0002 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode dummy = new ListNode(-1);
        ListNode tmp = dummy;
        int t = 0;
        while (t > 0 || l1 != null || l2 != null) {
            if (l1 != null) {
                t += l1.val;
                l1 = l1.next;
            }
            if (l2 != null) {
                t += l2.val;
                l2 = l2.next;
            }
            tmp.next = new ListNode(t % 10);
            tmp = tmp.next;
            t /= 10;
        }
        return dummy.next;
    }
}
